
package com.taco.springcloud.generate.model.dto;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.IdType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;

/**
 *  代码生成参数DTO
 *
 *  @author Yu
 *  @date 2019/10/3 16:14
 */
@Data
@ApiModel(value = "GenerateDTO", description = "代码生成参数DTO")
public class GenerateDTO implements Serializable {

    private static final long serialVersionUID = -1107000187365677319L;

    /**
     * 模块名称
     */
    @ApiModelProperty(value = "模块名称", example = "demo")
    private String moduleName;

    /**
     * 代码生成的类的父包名称
     */
    @ApiModelProperty(value = "代码生成的类的父包名称", example = "com.taco.springcloud")
    private String parentPackage;

    /**
     * Model包名
     */
    @ApiModelProperty(value = "Model包名", example = "model.po")
    private String modelPackage;

    /**
     * dao包名
     */
    @ApiModelProperty(value = "dao包名", example = "dao")
    private String daoPackage;

    /**
     * mapper.xml包名
     */
    @ApiModelProperty(value = "mapper.xml包名", example = "mapper")
    private String mapperPackage;

    /**
     * service包名
     */
    @ApiModelProperty(value = "service包名", example = "service")
    private String servicePackage;

    /**
     * controller包名
     */
    @ApiModelProperty(value = "controller包名", example = "web.controller")
    private String controllerPackage;

    /**
     * 去掉表的前缀
     */
    @ApiModelProperty(value = "去掉表的前缀（默认值tb_）", example = "tb_")
    private String tablePrefix = "tb_";

    /**生成ID类型*/
    @ApiModelProperty(value = "生成ID类型(AUTO:数据库ID自增,NONE:该类型为未设置主键类型(将跟随全局), INPUT:用户输入ID, ID_WORKER: 雪花id，UUID：UUID， ID_WORKER_STR：idWorker 的字符串表示", example = "AUTO")
    private String idType = "AUTO";

    /**
     * 代码生成包含的表，可为空，为空默认生成所有
     */
    @NotBlank(message = "包含表不能为空")
    @ApiModelProperty(value = "代码生成包含的表，可为空，为空默认生成所有", example = "tb_demo")
    private String includeTables;

    /**
     * 生成代码里，注释的作者
     */
    @ApiModelProperty(value = "生成代码里，注释的作者（默认值:yxy）", example = "yxy")
    private String author = "yxy";

    /**
     * 数据库类型
     */
    @NotBlank(message = "数据库类型不能为空")
    @ApiModelProperty(value = "数据库类型", example = "mysql")
    private String dbType;

    /**
     * jdbc驱动
     */
    @NotBlank(message = "jdbc驱动不能为空")
    @ApiModelProperty(value = "jdbc驱动", example = "com.mysql.cj.jdbc.Driver")
    private String driverName;

    /**
     * 数据库连接地址
     */
    @ApiModelProperty(value = "数据库连接地址", hidden = true, example = "jdbc:mysql://localhost:3306/test?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&tinyInt1isBit=false&serverTimezone=GMT%2B8")
    private String url;

    /**
     * 数据库连接地址
     */
    @NotBlank(message = "数据库连接地址不能为空")
    @ApiModelProperty(value = "数据库连接地址", example = "jdbc:mysql://localhost:3306")
    private String jdbcUrl;

    @NotBlank
    @ApiModelProperty(value = "名称空间（数据库名称）", example = "test")
    private String schema;

    /**
     * 数据库账号
     */
    @NotBlank(message = "数据库账号不能为空")
    @ApiModelProperty(value = "数据库账号", example = "user")
    private String username;

    /**
     * 数据库密码
     */
    @NotBlank(message = "数据库密码不能为空")
    @ApiModelProperty(value = "数据库密码", example = "password")
    private String password;

    /**
     * 代码生成目录
     */
    @ApiModelProperty(value = "代码生成目录", hidden = true)
    private String outputDir;

    @ApiModelProperty(hidden = true)
    public String[] getTablePrefixArr() {
        return tablePrefix.split(",");
    }

    @ApiModelProperty(hidden = true)
    public String[] getIncludeTablesArr() {
        return includeTables.split(",");
    }

    @ApiModelProperty(hidden = true)
    public DbType getDbType() {
        return DbType.getDbType(dbType);
    }

    public String getUrl() {
        return jdbcUrl + "/" + schema + "?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&tinyInt1isBit=false&serverTimezone=GMT%2B8";
    }

}
